package com.apes.hr.base.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.Name;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.plugin.fileserver.File;
import com.apes.framework.util.DateUtil;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Date;

/**
 * 功能：员工技能证书
 *
 * @author Fengjiajing
 * @create 2018-09-17 11:11
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = EmployeeSkillCertificate.CONST_TABLE_NAME)
public class EmployeeSkillCertificate extends Model {
    public static final String CONST_TABLE_NAME = "hr_Employee_Skill_Certificate";

    @Id
    @Column(name = "id")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "员工技能证书", numberNext = 20000)
    @Comment("编码")
    private Integer id; //编码

    @Name
    @Column(name = "cert_number", length = 32)
    @Comment("技能证书号码")
    private String certNumber; //技能证书号码

    @ManyToOne
    @JoinColumn(name = "employee_id", referencedColumnName = "id")
    @Comment("所属人")
    private Employee employee;

    @ManyToOne
    @JoinColumn(name = "talent_pool_id", referencedColumnName = "id")
    @Comment("人才储备")
    private TalentPool talentPool; //人才储备

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "skill_type_ID", referencedColumnName = "ID", nullable = false)
    @Comment("技能证书类型")
    private SkillType skillType;  //技能证书类型

//    @ManyToOne(optional = false)
//    @JoinColumn(name="skill_level_ID", referencedColumnName="ID", nullable = false)
//    private SkillLevel skillLevel;  //技能证书等级

    @Column(name = "issuing_organ", length = 50)
    @Comment("发证机关")
    private String issuingOrgan; //发证机关

    @Column(name = "qualification", length = 50)
    @Comment("熟练程度")
    private String qualification;  //熟练程度

    @Column(name = "DESCRIPTION", length = 255)
    @Comment("说明")
    private String description; //说明

    @JSONField(format = DateUtil.SHOW_DATE_FORMAT)
    @Temporal(TemporalType.DATE)
    @Column(name = "issuing_date")
    @Comment("颁发日期")
    private Date issuingDate; //颁发日期

    @Column(name = "effective_age", columnDefinition = "number(8,0) default 0")
    @Comment("有效年限")
    private int effectiveAge = 0; //有效年限

    @Column(name = "has_record", columnDefinition = "number(1,0) default 0")
    @Comment("是否备案")
    private boolean hasRecord = false; //是否备案

    @File
    @Lob
    @Basic(fetch = FetchType.LAZY)
    @Column(name = "skill_photos", columnDefinition = "CLOB")
    @Comment("技能证书图片")
    private String skillPhotos;
}
